package com.ciaojian.client.factory;

import com.ciaojian.client.enums.DiscountTypeEnum;
import com.ciaojian.client.strategy.discount.DiscountCalculator;

import java.util.HashMap;
import java.util.Map;

/**
 * 订单优惠计算器工厂类
 * 用于获取优惠处理方法
 *
 * @author oxiny
 */
public class DiscountCalculatorFactory {
    /**
     * 存放所有的价格计算器
     */
    private static Map<DiscountTypeEnum, DiscountCalculator> MAP = new HashMap<>();

    public static DiscountCalculator get(DiscountTypeEnum discountType) {
        return MAP.get(discountType);
    }

    /**
     * 注册计算器策略
     *
     * @param discountCalculator 价格计算器
     */
    public static <T> void register(DiscountCalculator<T> discountCalculator) {
        MAP.put(discountCalculator.getType(), discountCalculator);
    }
}
